package com.woohua.thread.life;

/***
 * @title LifeCycleDemo2
 * @description
 * @author woo hua
 * @version 1.0.0
 * @create 2023/3/10 13:30
 **/
public class LifeCycleDemo2 {

    public static void main(String[] args) {
        Thread t0 = new Thread(new ChildThread(Thread.currentThread()));

        t0.start();
        // 子线程启动后状态为 RUNNABLE
        printState(t0);
        // 主线程启动后状态为 RUNNABLE
        printState(Thread.currentThread());

        try {
            // 子线程join 后， 主线程状态为 WAITING
            t0.join();

            // 主线程状态为 RUNNABLE
            printState(Thread.currentThread());

            // 子线程运行结束，状态为 TERMINATED
            printState(t0);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }

    private static void printState(Thread t) {
        System.out.println(t.getName() + " " + t.getState());
    }
}
